package diamondRingServlet;

import diamondRingEntity.Admin;
import diamondRingService.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/*
按用户id修改用户信息
 */
@WebServlet("/UpdateAdminInfoServlet")
public class BackUpdateAdminInfoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码格式
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        HttpSession session = request.getSession();
        PrintWriter out=response.getWriter();

        AdminServiceImpl adminService = new AdminServiceImpl();

        int count = 0;

        String ID = request.getParameter("ID");
        System.out.println(ID);
        String adminName = request.getParameter("adminName");
        System.out.println(adminName);
        String adminsex = request.getParameter("adminsex");
        System.out.println(adminsex);
        String adminBrithday = request.getParameter("adminBrithday");
        System.out.println(adminBrithday);
        String adminPhone = request.getParameter("adminPhone");
        System.out.println(adminPhone);
        String adminAdeessr = request.getParameter("adminAdeessr");
        System.out.println(adminAdeessr);

        Admin admin = new Admin(adminName,adminsex,adminBrithday,adminPhone,adminAdeessr);

        if (adminService.UpdateAdminInfo(admin,ID)>0){
            count = 1;
        }else{
            count = -1;
        }
        out.print(count);
        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
